Conditions | 218 |
Total Lines | 823 |
Code Lines | 514 |
Lines | 407 |
Ratio | 49.45 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like dhtmlxmenu.js ➔ dhtmlXMenuObject often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | //v.3.6 build 131108 |
||
13 | function dhtmlXMenuObject(baseId, skin) { |
||
14 | var main_self = this; |
||
15 | |||
16 | this.addBaseIdAsContextZone = null; |
||
17 | |||
18 | this.isDhtmlxMenuObject = true; |
||
19 | |||
20 | // skin settings |
||
21 | this.skin = (skin != null ? skin : (typeof(dhtmlx) != "undefined" && typeof(dhtmlx.skin) == "string" ? dhtmlx.skin : "dhx_skyblue")); |
||
22 | this.imagePath = ""; |
||
23 | |||
24 | // iframe |
||
25 | this._isIE6 = false; |
||
26 | if (_isIE) this._isIE6 = (window.XMLHttpRequest==null?true:false); |
||
27 | |||
28 | if (baseId == null) { |
||
29 | this.base = document.body; |
||
30 | } else { |
||
31 | var baseObj = (typeof(baseId)=="string"?document.getElementById(baseId):baseId); |
||
32 | if (baseObj != null) { |
||
33 | this.base = baseObj; |
||
34 | if (!this.base.id) this.base.id = (new Date()).valueOf(); |
||
35 | while (this.base.childNodes.length > 0) { this.base.removeChild(this.base.childNodes[0]); } |
||
36 | this.base.className += " dhtmlxMenu_"+this.skin+"_Middle dir_left"; |
||
37 | this.base._autoSkinUpdate = true; |
||
38 | // preserv default oncontextmenu for future restorin in case of context menu |
||
39 | if (this.base.oncontextmenu) this.base._oldContextMenuHandler = this.base.oncontextmenu; |
||
40 | // |
||
41 | this.addBaseIdAsContextZone = this.base.id; |
||
42 | this.base.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; } |
||
43 | this.base.oncontextmenu = function(e) { e = e || event; e.returnValue = false; return false; } |
||
44 | } else { |
||
45 | this.base = document.body; |
||
46 | } |
||
47 | } |
||
48 | // this.topId = topId; |
||
49 | this.topId = "dhxWebMenuTopId"; |
||
50 | |||
51 | // |
||
52 | if (!this.extendedModule) { |
||
53 | // add notify for menu |
||
54 | var t = function(){alert(this.i18n.dhxmenuextalert);}; |
||
55 | var extMethods = new Array("setItemEnabled", "setItemDisabled", "isItemEnabled", "_changeItemState", "getItemText", "setItemText", |
||
56 | "loadFromHTML", "hideItem", "showItem", "isItemHidden", "_changeItemVisible", "setUserData", "getUserData", |
||
57 | "setOpenMode", "setWebModeTimeout", "enableDynamicLoading", "_updateLoaderIcon", "getItemImage", "setItemImage", |
||
58 | "clearItemImage", "setAutoShowMode", "setAutoHideMode", "setContextMenuHideAllMode", "getContextMenuHideAllMode", |
||
59 | "setVisibleArea", "setTooltip", "getTooltip", "setHotKey", "getHotKey", "setItemSelected", "setTopText", "setRTL", |
||
60 | "setAlign", "setHref", "clearHref", "getCircuit", "_clearAllSelectedSubItemsInPolygon", "_checkArrowsState", |
||
61 | "_addUpArrow", "_addDownArrow", "_removeUpArrow", "_removeDownArrow", "_isArrowExists", "_doScrollUp", "_doScrollDown", |
||
62 | "_countPolygonItems", "setOverflowHeight", "_getRadioImgObj", "_setRadioState", "_radioOnClickHandler", |
||
63 | "getRadioChecked", "setRadioChecked", "addRadioButton", "_getCheckboxState", "_setCheckboxState", "_readLevel", |
||
64 | "_updateCheckboxImage", "_checkboxOnClickHandler", "setCheckboxState", "getCheckboxState", "addCheckbox", "serialize"); |
||
65 | for (var q=0; q<extMethods.length; q++) if (!this[extMethods[q]]) this[extMethods[q]] = t; |
||
66 | extMethods = null; |
||
67 | } |
||
68 | |||
69 | // should be used for frameset in IE |
||
70 | this.fixedPosition = false; |
||
71 | |||
72 | this.menuSelected = -1; |
||
73 | this.menuLastClicked = -1; |
||
74 | this.idPrefix = ""; |
||
75 | this.itemTagName = "item"; |
||
76 | this.itemTextTagName = "itemtext"; |
||
77 | this.userDataTagName = "userdata"; |
||
78 | this.itemTipTagName = "tooltip"; |
||
79 | this.itemHotKeyTagName = "hotkey"; |
||
80 | this.itemHrefTagName = "href"; |
||
81 | this.dirTopLevel = "bottom"; |
||
82 | this.dirSubLevel = "right"; |
||
83 | this.menuX1 = null; |
||
84 | this.menuX2 = null; |
||
85 | this.menuY1 = null; |
||
86 | this.menuY2 = null; |
||
87 | this.menuMode = "web"; |
||
88 | this.menuTimeoutMsec = 400; |
||
89 | this.menuTimeoutHandler = null; |
||
90 | this.autoOverflow = false; |
||
91 | this.idPull = {}; |
||
92 | this.itemPull = {}; |
||
93 | this.userData = {}; |
||
94 | this.radio = {}; |
||
95 | // |
||
96 | this._rtl = false; |
||
97 | this._align = "left"; |
||
98 | // |
||
99 | this.menuTouched = false; |
||
100 | // |
||
101 | this.zIndInit = 1200; |
||
102 | this.zInd = this.zIndInit; |
||
103 | this.zIndStep = 50; |
||
104 | // |
||
105 | this.menuModeTopLevelTimeout = true; // shows sublevel polygons from toplevel items with delay |
||
106 | this.menuModeTopLevelTimeoutTime = 200; // msec |
||
107 | // |
||
108 | // default skin |
||
109 | // this.skin = "Standard"; |
||
110 | |||
111 | // skin-based params |
||
112 | this._topLevelBottomMargin = 1; |
||
113 | this._topLevelRightMargin = 0; |
||
114 | this._topLevelOffsetLeft = 1; |
||
115 | this._arrowFFFix = (_isIE?(document.compatMode=="BackCompat"?0:-4):-4); // border fixer for FF for arrows polygons |
||
116 | |||
117 | /** |
||
118 | * @desc: changes menu skin |
||
119 | * @param: skin - skin name |
||
120 | * @type: public |
||
121 | */ |
||
122 | View Code Duplication | this.setSkin = function(skin) { |
|
123 | var oldSkin = this.skin; |
||
124 | this.skin = skin; |
||
125 | switch (this.skin){ |
||
126 | case "dhx_black": |
||
127 | case "dhx_blue": |
||
128 | case "dhx_skyblue": |
||
129 | case "dhx_web": |
||
130 | this._topLevelBottomMargin = 2; |
||
131 | this._topLevelRightMargin = 1; |
||
132 | this._topLevelOffsetLeft = 1; |
||
133 | this._arrowFFFix = (_isIE?(document.compatMode=="BackCompat"?0:-4):-4); |
||
134 | break; |
||
135 | case "dhx_web": |
||
136 | this._arrowFFFix = 0; |
||
137 | break; |
||
138 | case "dhx_terrace": |
||
139 | this._topLevelBottomMargin = 0; |
||
140 | this._topLevelRightMargin = 0; |
||
141 | this._topLevelOffsetLeft = 0; |
||
142 | this._arrowFFFix = (_isIE?(document.compatMode=="BackCompat"?0:-4):-4); |
||
143 | break; |
||
144 | } |
||
145 | if (this.base._autoSkinUpdate) { |
||
146 | this.base.className = this.base.className.replace("dhtmlxMenu_"+oldSkin+"_Middle", "")+" dhtmlxMenu_"+this.skin+"_Middle"; |
||
147 | } |
||
148 | |||
149 | for (var a in this.idPull) { |
||
150 | this.idPull[a].className = String(this.idPull[a].className).replace(oldSkin, this.skin); |
||
151 | |||
152 | } |
||
153 | } |
||
154 | this.setSkin(this.skin); |
||
155 | // |
||
156 | this.dLoad = false; |
||
157 | this.dLoadUrl = ""; |
||
158 | this.dLoadSign = "?"; |
||
159 | this.loaderIcon = false; |
||
160 | this.limit = 0; |
||
161 | // |
||
162 | this._scrollUpTM = null; |
||
163 | this._scrollUpTMTime = 20; |
||
164 | this._scrollUpTMStep = 3; |
||
165 | this._scrollDownTM = null; |
||
166 | this._scrollDownTMTime = 20; |
||
167 | this._scrollDownTMStep = 3; |
||
168 | /* context menu */ |
||
169 | this.context = false; |
||
170 | this.contextZones = {}; |
||
171 | this.contextMenuZoneId = false; |
||
172 | this.contextAutoShow = true; /* default open action */ |
||
173 | this.contextAutoHide = true; /* default close action */ |
||
174 | this.contextHideAllMode = true; /* true will hide all opened contextual menu polygons on mouseout, false - all except topleft */ |
||
175 | |||
176 | this._selectedSubItems = new Array(); |
||
177 | this._openedPolygons = new Array(); |
||
178 | this._addSubItemToSelected = function(item, polygon) { |
||
179 | var t = true; |
||
180 | for (var q=0; q<this._selectedSubItems.length; q++) { if ((this._selectedSubItems[q][0] == item) && (this._selectedSubItems[q][1] == polygon)) { t = false; } } |
||
181 | if (t == true) { this._selectedSubItems.push(new Array(item, polygon)); } |
||
182 | return t; |
||
183 | } |
||
184 | View Code Duplication | this._removeSubItemFromSelected = function(item, polygon) { |
|
185 | var m = new Array(); |
||
186 | var t = false; |
||
187 | for (var q=0; q<this._selectedSubItems.length; q++) { if ((this._selectedSubItems[q][0] == item) && (this._selectedSubItems[q][1] == polygon)) { t = true; } else { m[m.length] = this._selectedSubItems[q]; } } |
||
188 | if (t == true) { this._selectedSubItems = m; } |
||
189 | return t; |
||
190 | } |
||
191 | View Code Duplication | this._getSubItemToDeselectByPolygon = function(polygon) { |
|
192 | var m = new Array(); |
||
193 | for (var q=0; q<this._selectedSubItems.length; q++) { |
||
194 | if (this._selectedSubItems[q][1] == polygon) { |
||
195 | m[m.length] = this._selectedSubItems[q][0]; |
||
196 | m = m.concat(this._getSubItemToDeselectByPolygon(this._selectedSubItems[q][0])); |
||
197 | var t = true; |
||
198 | for (var w=0; w<this._openedPolygons.length; w++) { if (this._openedPolygons[w] == this._selectedSubItems[q][0]) { t = false; } } |
||
199 | if (t == true) { this._openedPolygons[this._openedPolygons.length] = this._selectedSubItems[q][0]; } |
||
200 | this._selectedSubItems[q][0] = -1; |
||
201 | this._selectedSubItems[q][1] = -1; |
||
202 | } |
||
203 | } |
||
204 | return m; |
||
205 | } |
||
206 | /* end */ |
||
207 | /* define polygon's position for dinamic content rendering and shows it, added in version 0.3 */ |
||
208 | View Code Duplication | this._hidePolygon = function(id) { |
|
209 | if (this.idPull["polygon_" + id] != null) { |
||
210 | if (typeof(this._menuEffect) != "undefined" && this._menuEffect !== false) { |
||
211 | this._hidePolygonEffect("polygon_"+id); |
||
212 | } else { |
||
213 | // already hidden |
||
214 | if (this.idPull["polygon_"+id].style.display == "none") return; |
||
215 | // |
||
216 | this.idPull["polygon_"+id].style.display = "none"; |
||
217 | if (this.idPull["arrowup_"+id] != null) { this.idPull["arrowup_"+id].style.display = "none"; } |
||
218 | if (this.idPull["arrowdown_"+id] != null) { this.idPull["arrowdown_"+id].style.display = "none"; } |
||
219 | this._updateItemComplexState(id, true, false); |
||
220 | // hide ie6 cover |
||
221 | if (this._isIE6) { if (this.idPull["polygon_"+id+"_ie6cover"] != null) { this.idPull["polygon_"+id+"_ie6cover"].style.display = "none"; } } |
||
222 | } |
||
223 | // call event |
||
224 | id = String(id).replace(this.idPrefix, ""); |
||
225 | if (id == this.topId) id = null; |
||
226 | this.callEvent("onHide", [id]); |
||
227 | |||
228 | // corners |
||
229 | if (id != null && this.skin == "dhx_terrace" && this.itemPull[this.idPrefix+id].parent == this.idPrefix+this.topId) { |
||
230 | this._improveTerraceButton(this.idPrefix+id, true); |
||
231 | } |
||
232 | |||
233 | |||
234 | } |
||
235 | } |
||
236 | this._showPolygon = function(id, openType) { |
||
237 | |||
238 | var itemCount = this._countVisiblePolygonItems(id); |
||
239 | if (itemCount == 0) return; |
||
240 | var pId = "polygon_"+id; |
||
241 | if ((this.idPull[pId] != null) && (this.idPull[id] != null)) { |
||
242 | |||
243 | if (this.menuModeTopLevelTimeout && this.menuMode == "web" && !this.context) { |
||
244 | if (!this.idPull[id]._mouseOver && openType == this.dirTopLevel) return; |
||
245 | } |
||
246 | |||
247 | // detect visible area |
||
248 | if (!this.fixedPosition) this._autoDetectVisibleArea(); |
||
249 | |||
250 | // show arrows |
||
251 | var arrUpH = 0; |
||
252 | var arrDownH = 0; |
||
253 | // |
||
254 | var arrowUp = null; |
||
255 | var arrowDown = null; |
||
256 | |||
257 | // show polygon |
||
258 | this.idPull[pId].style.visibility = "hidden"; |
||
259 | this.idPull[pId].style.left = "0px"; |
||
260 | this.idPull[pId].style.top = "0px"; |
||
261 | this.idPull[pId].style.display = ""; |
||
262 | this.idPull[pId].style.zIndex = this.zInd; |
||
263 | |||
264 | // |
||
265 | View Code Duplication | if (this.autoOverflow) { |
|
266 | if (this.idPull[pId].firstChild.offsetHeight > this.menuY1+this.menuY2) { |
||
267 | var t0 = Math.floor((this.menuY2-this.menuY1-35)/24); |
||
268 | this.limit = t0; |
||
269 | } else { |
||
270 | this.limit = 0; |
||
271 | |||
272 | if (this.idPull["arrowup_"+id] != null) this._removeUpArrow(String(id).replace(this.idPrefix,"")); |
||
273 | if (this.idPull["arrowdown_"+id] != null) this._removeDownArrow(String(id).replace(this.idPrefix,"")); |
||
274 | } |
||
275 | } |
||
276 | |||
277 | //#menu_overflow:06062008#{ |
||
278 | View Code Duplication | if (this.limit > 0 && this.limit < itemCount) { |
|
279 | |||
280 | // add overflow arrows if they not exists |
||
281 | if (this.idPull["arrowup_"+id] == null) this._addUpArrow(String(id).replace(this.idPrefix,"")); |
||
282 | if (this.idPull["arrowdown_"+id] == null) this._addDownArrow(String(id).replace(this.idPrefix,"")); |
||
283 | |||
284 | // configure up arrow |
||
285 | arrowUp = this.idPull["arrowup_"+id]; |
||
286 | arrowUp.style.visibility = "hidden"; |
||
287 | arrowUp.style.display = ""; |
||
288 | arrowUp.style.zIndex = this.zInd; |
||
289 | arrUpH = arrowUp.offsetHeight; |
||
290 | |||
291 | // configure bottom arrow |
||
292 | arrowDown = this.idPull["arrowdown_"+id]; |
||
293 | arrowDown.style.visibility = "hidden"; |
||
294 | arrowDown.style.display = ""; |
||
295 | arrowDown.style.zIndex = this.zInd; |
||
296 | arrDownH = arrowDown.offsetHeight; |
||
297 | } |
||
298 | //#} |
||
299 | |||
300 | if (this.limit > 0) { |
||
301 | if (this.limit < itemCount) { |
||
302 | // set fixed size |
||
303 | // this.idPull[pId].style.height = this.idPull[pId].tbd.childNodes[0].offsetHeight*this.limit+"px";// + arrUpH + arrDownH; |
||
304 | this.idPull[pId].style.height = 24*this.limit+"px"; |
||
305 | this.idPull[pId].scrollTop = 0; |
||
306 | } else { |
||
307 | // remove fixed size |
||
308 | this.idPull[pId].style.height = ""; |
||
309 | } |
||
310 | } |
||
311 | // |
||
312 | this.zInd += this.zIndStep; |
||
313 | // |
||
314 | // console.log(this.idPull) |
||
315 | if (this.itemPull[id] != null) { |
||
316 | var parPoly = "polygon_"+this.itemPull[id]["parent"]; |
||
317 | } else if (this.context) { |
||
318 | var parPoly = this.idPull[this.idPrefix+this.topId]; |
||
319 | } |
||
320 | /* |
||
321 | // debug info |
||
322 | if (parPoly == null) { |
||
323 | alert("Implementation error. Please report [email protected]"); |
||
324 | } |
||
325 | */ |
||
326 | // |
||
327 | // |
||
328 | // define position |
||
329 | var srcX = (this.idPull[id].tagName != null ? getAbsoluteLeft(this.idPull[id]) : this.idPull[id][0]); |
||
330 | var srcY = (this.idPull[id].tagName != null ? getAbsoluteTop(this.idPull[id]) : this.idPull[id][1]); |
||
331 | var srcW = (this.idPull[id].tagName != null ? this.idPull[id].offsetWidth : 0); |
||
332 | var srcH = (this.idPull[id].tagName != null ? this.idPull[id].offsetHeight : 0); |
||
333 | |||
334 | var x = 0; |
||
335 | var y = 0; |
||
336 | var w = this.idPull[pId].offsetWidth; |
||
337 | var h = this.idPull[pId].offsetHeight + arrUpH + arrDownH; |
||
338 | |||
339 | //console.log(srcY,h,window.innerHeight,document.body.scrollTop) |
||
340 | /* |
||
341 | var bottomOverflow = (srcY+h > window.innerHeight+document.body.scrollTop); |
||
342 | if (bottomOverflow) { |
||
343 | if (openType == "bottom") openType = "top"; |
||
344 | if (openType == "right" || openType == "left") { |
||
345 | srcY = srcY-h; |
||
346 | } |
||
347 | } |
||
348 | */ |
||
349 | // pos |
||
350 | View Code Duplication | if (openType == "bottom") { |
|
351 | if (this._rtl) { |
||
352 | x = srcX + (srcW!=null?srcW:0) - w; |
||
353 | } else { |
||
354 | if (this._align == "right") { |
||
355 | x = srcX + srcW - w; |
||
356 | } else { |
||
357 | x = srcX - 1 + (openType==this.dirTopLevel?this._topLevelRightMargin:0); |
||
358 | } |
||
359 | } |
||
360 | y = srcY - 1 + srcH + this._topLevelBottomMargin; |
||
361 | } |
||
362 | if (openType == "right") { x = srcX + srcW - 1; y = srcY + 2; } |
||
363 | if (openType == "left") { x = srcX - this.idPull[pId].offsetWidth + 2; y = srcY + 2; } |
||
364 | if (openType == "top") { x = srcX - 1; y = srcY - h + 2; } |
||
365 | |||
366 | // overflow check |
||
367 | View Code Duplication | if (this.fixedPosition) { |
|
368 | // use fixed document.body/window dimension if required |
||
369 | var mx = 65536; |
||
370 | var my = 65536; |
||
371 | } else { |
||
372 | var mx = (this.menuX2!=null?this.menuX2:0); |
||
373 | var my = (this.menuY2!=null?this.menuY2:0); |
||
374 | |||
375 | if (mx == 0) { |
||
376 | if (window.innerWidth) { |
||
377 | mx = window.innerWidth; |
||
378 | my = window.innerHeight; |
||
379 | } else { |
||
380 | mx = document.body.offsetWidth; |
||
381 | my = document.body.scrollHeight; |
||
382 | } |
||
383 | } |
||
384 | } |
||
385 | if (x+w > mx && !this._rtl) { |
||
386 | // no space on right, open to left |
||
387 | x = srcX - w + 2; |
||
388 | } |
||
389 | if (x < this.menuX1 && this._rtl) { |
||
390 | // no space on left, open to right |
||
391 | x = srcX + srcW - 2; |
||
392 | } |
||
393 | if (x < 0) { |
||
394 | // menu floats left |
||
395 | x = 0; |
||
396 | } |
||
397 | if (y+h > my && this.menuY2 != null) { |
||
398 | y = Math.max(srcY + srcH - h + 2, (this._isVisibleArea?this.menuY1+2:2)); |
||
399 | // open from top level |
||
400 | if (this.context && this.idPrefix+this.topId == id && arrowDown != null) { |
||
401 | // autoscroll prevent because menu mouse pointer will right over downarrow |
||
402 | y = y-2; |
||
403 | } |
||
404 | if (this.itemPull[id] != null && !this.context) { |
||
405 | if (this.itemPull[id]["parent"] == this.idPrefix+this.topId) y = y - this.base.offsetHeight; |
||
406 | } |
||
407 | } |
||
408 | // |
||
409 | this.idPull[pId].style.left = x+"px"; |
||
410 | this.idPull[pId].style.top = y+arrUpH+"px"; |
||
411 | // |
||
412 | if (typeof(this._menuEffect) != "undefined" && this._menuEffect !== false) { |
||
413 | this._showPolygonEffect(pId); |
||
414 | } else { |
||
415 | this.idPull[pId].style.visibility = ""; |
||
416 | //#menu_overflow:06062008#{ |
||
417 | View Code Duplication | if (this.limit > 0 && this.limit < itemCount) { |
|
418 | // this.idPull[pId].scrollTop = 0; |
||
419 | arrowUp.style.left = x+"px"; |
||
420 | arrowUp.style.top = y+"px"; |
||
421 | arrowUp.style.width = w+this._arrowFFFix+"px"; |
||
422 | arrowUp.style.visibility = ""; |
||
423 | // |
||
424 | arrowDown.style.left = x+"px"; |
||
425 | arrowDown.style.top = y+h-arrDownH+"px"; |
||
426 | arrowDown.style.width = w+this._arrowFFFix+"px"; |
||
427 | arrowDown.style.visibility = ""; |
||
428 | // |
||
429 | this._checkArrowsState(id); |
||
430 | } |
||
431 | //#} |
||
432 | // show ie6 cover |
||
433 | if (this._isIE6) { |
||
434 | var pIdIE6 = pId+"_ie6cover"; |
||
435 | if (this.idPull[pIdIE6] == null) { |
||
436 | var ifr = document.createElement("IFRAME"); |
||
437 | ifr.className = "dhtmlxMenu_IE6CoverFix_"+this.skin; |
||
438 | ifr.frameBorder = 0; |
||
439 | ifr.setAttribute("src", "javascript:false;"); |
||
440 | document.body.insertBefore(ifr, document.body.firstChild); |
||
441 | this.idPull[pIdIE6] = ifr; |
||
442 | } |
||
443 | this.idPull[pIdIE6].style.left = x+"px"; |
||
444 | this.idPull[pIdIE6].style.top = y+"px"; |
||
445 | this.idPull[pIdIE6].style.width = w+"px"; |
||
446 | this.idPull[pIdIE6].style.height = h+"px"; |
||
447 | this.idPull[pIdIE6].style.zIndex = this.idPull[pId].style.zIndex-1; |
||
448 | this.idPull[pIdIE6].style.display = ""; |
||
449 | } |
||
450 | } |
||
451 | |||
452 | id = String(id).replace(this.idPrefix, ""); |
||
453 | if (id == this.topId) id = null; |
||
454 | this.callEvent("onShow", [id]); |
||
455 | |||
456 | // corners |
||
457 | if (id != null && this.skin == "dhx_terrace" && this.itemPull[this.idPrefix+id].parent == this.idPrefix+this.topId) { |
||
458 | this._improveTerraceButton(this.idPrefix+id, false); |
||
459 | } |
||
460 | // this.callEvent("_onPolyShow",[id.replace(this.idPrefix,"")]); |
||
461 | |||
462 | } |
||
463 | } |
||
464 | /* redistrib sublevel selection: select id and deselect other, added in version 0.3 */ |
||
465 | View Code Duplication | this._redistribSubLevelSelection = function(id, parentId) { |
|
466 | // clear previosly selected items |
||
467 | while (this._openedPolygons.length > 0) this._openedPolygons.pop(); |
||
468 | // this._openedPolygons = new Array(); |
||
469 | var i = this._getSubItemToDeselectByPolygon(parentId); |
||
470 | this._removeSubItemFromSelected(-1, -1); |
||
471 | for (var q=0; q<i.length; q++) { if ((this.idPull[i[q]] != null) && (i[q] != id)) { if (this.itemPull[i[q]]["state"] == "enabled") { this.idPull[i[q]].className = "sub_item"; } } } |
||
472 | // hide polygons |
||
473 | for (var q=0; q<this._openedPolygons.length; q++) { if (this._openedPolygons[q] != parentId) { this._hidePolygon(this._openedPolygons[q]); } } |
||
474 | // add new selection into list new |
||
475 | if (this.itemPull[id]["state"] == "enabled") { |
||
476 | this.idPull[id].className = "sub_item_selected"; |
||
477 | if (this.itemPull[id]["complex"] && this.dLoad && (this.itemPull[id]["loaded"]=="no")) { |
||
478 | if (this.loaderIcon == true) { this._updateLoaderIcon(id, true); } |
||
479 | var xmlLoader = new dtmlXMLLoaderObject(this._xmlParser, window); |
||
480 | this.itemPull[id]["loaded"] = "get"; |
||
481 | this.callEvent("onXLS", []); |
||
482 | xmlLoader.loadXML(this.dLoadUrl+this.dLoadSign+"action=loadMenu&parentId="+id.replace(this.idPrefix,"")+"&etc="+new Date().getTime()); |
||
483 | } |
||
484 | // show |
||
485 | if (this.itemPull[id]["complex"] || (this.dLoad && (this.itemPull[id]["loaded"] == "yes"))) { |
||
486 | // make arrow over |
||
487 | if ((this.itemPull[id]["complex"]) && (this.idPull["polygon_" + id] != null)) { |
||
488 | this._updateItemComplexState(id, true, true); |
||
489 | this._showPolygon(id, this.dirSubLevel); |
||
490 | } |
||
491 | } |
||
492 | this._addSubItemToSelected(id, parentId); |
||
493 | this.menuSelected = id; |
||
494 | } |
||
495 | } |
||
496 | /* onClickMenu action (click on any end item to perform some actions) |
||
497 | optimized in version 0.3 added type feature (click on disabled items, click on complex nodes) |
||
498 | attachEvent feature from 0.4 */ |
||
499 | View Code Duplication | this._doOnClick = function(id, type, casState) { |
|
500 | this.menuLastClicked = id; |
||
501 | // href |
||
502 | if (this.itemPull[this.idPrefix+id]["href_link"] != null && this.itemPull[this.idPrefix+id].state == "enabled") { |
||
503 | var form = document.createElement("FORM"); |
||
504 | var k = String(this.itemPull[this.idPrefix+id]["href_link"]).split("?"); |
||
505 | form.action = k[0]; |
||
506 | if (k[1] != null) { |
||
507 | var p = String(k[1]).split("&"); |
||
508 | for (var q=0; q<p.length; q++) { |
||
509 | var j = String(p[q]).split("="); |
||
510 | var m = document.createElement("INPUT"); |
||
511 | m.type = "hidden"; |
||
512 | m.name = (j[0]||""); |
||
513 | m.value = (j[1]||""); |
||
514 | form.appendChild(m); |
||
515 | } |
||
516 | } |
||
517 | if (this.itemPull[this.idPrefix+id]["href_target"] != null) { form.target = this.itemPull[this.idPrefix+id]["href_target"]; } |
||
518 | form.style.display = "none"; |
||
519 | document.body.appendChild(form); |
||
520 | form.submit(); |
||
521 | if (form != null) { |
||
522 | document.body.removeChild(form); |
||
523 | form = null; |
||
524 | } |
||
525 | return; |
||
526 | } |
||
527 | // |
||
528 | // some fixes |
||
529 | if (type.charAt(0)=="c") return; // can't click on complex item |
||
530 | if (type.charAt(1)=="d") return; // can't click on disabled item |
||
531 | if (type.charAt(2)=="s") return; // can't click on separator |
||
532 | // |
||
533 | if (this.checkEvent("onClick")) { |
||
534 | // this.callEvent("onClick", [id, type, this.contextMenuZoneId]); |
||
535 | this.callEvent("onClick", [id, this.contextMenuZoneId, casState]); |
||
536 | } else { |
||
537 | if ((type.charAt(1) == "d") || (this.menuMode == "win" && type.charAt(2) == "t")) return; |
||
538 | } |
||
539 | if (this.context && this._isContextMenuVisible() && this.contextAutoHide) { |
||
540 | this._hideContextMenu(); |
||
541 | } else { |
||
542 | // if menu unloaded from click event |
||
543 | if (this._clearAndHide) this._clearAndHide(); |
||
544 | } |
||
545 | } |
||
546 | /* onTouchMenu action (select topLevel item), attachEvent added in 0.4 */ |
||
547 | this._doOnTouchMenu = function(id) { |
||
548 | if (this.menuTouched == false) { |
||
549 | this.menuTouched = true; |
||
550 | if (this.checkEvent("onTouch")) { |
||
551 | this.callEvent("onTouch", [id]); |
||
552 | } |
||
553 | } |
||
554 | } |
||
555 | // this._onTouchHandler = function(id) { } |
||
556 | // this._setOnTouchHandler = function(handler) { this._onTouchHandler = function(id) { handler(id); } } |
||
557 | /* return menu array of all nested objects */ |
||
558 | View Code Duplication | this._searchMenuNode = function(node, menu) { |
|
559 | var m = new Array(); |
||
560 | for (var q=0; q<menu.length; q++) { |
||
561 | if (typeof(menu[q]) == "object") { |
||
562 | if (menu[q].length == 5) { if (typeof(menu[q][0]) != "object") { if ((menu[q][0].replace(this.idPrefix, "") == node) && (q == 0)) { m = menu; } } } |
||
563 | var j = this._searchMenuNode(node, menu[q]); |
||
564 | if (j.length > 0) { m = j; } |
||
565 | } |
||
566 | } |
||
567 | return m; |
||
568 | } |
||
569 | /* return array of subitems for single menu object */ |
||
570 | /* modified in version 0.3 */ |
||
571 | this._getMenuNodes = function(node) { |
||
572 | var m = new Array; |
||
573 | for (var a in this.itemPull) { if (this.itemPull[a]["parent"] == node) { m[m.length] = a; } } |
||
574 | return m; |
||
575 | } |
||
576 | /* generate random string with specified length */ |
||
577 | this._genStr = function(w) { |
||
578 | var s = ""; var z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
||
579 | for (var q=0; q<w; q++) s += z.charAt(Math.round(Math.random() * (z.length-1))); |
||
580 | return s; |
||
581 | } |
||
582 | /** |
||
583 | * @desc: return item type by id |
||
584 | * @param: id |
||
585 | * @type: public |
||
586 | */ |
||
587 | this.getItemType = function(id) { |
||
588 | id = this.idPrefix+id; |
||
589 | if (this.itemPull[id] == null) { return null; } |
||
590 | return this.itemPull[id]["type"]; |
||
591 | } |
||
592 | /* |
||
593 | * @desc: iterator, calls user-defined handler for each existing item and pass item id into it |
||
594 | * @param: handler - user-defined handler |
||
595 | * @type: public |
||
596 | */ |
||
597 | this.forEachItem = function(handler) { |
||
598 | for (var a in this.itemPull) { handler(String(a).replace(this.idPrefix, "")); } |
||
599 | } |
||
600 | /* clear selection and hide menu on onbody click event, optimized in version 0.3 */ |
||
601 | View Code Duplication | this._clearAndHide = function() { |
|
602 | main_self.menuSelected = -1; |
||
603 | main_self.menuLastClicked = -1; |
||
604 | while (main_self._openedPolygons.length > 0) { main_self._openedPolygons.pop(); } |
||
605 | for (var q=0; q<main_self._selectedSubItems.length; q++) { |
||
606 | var id = main_self._selectedSubItems[q][0]; |
||
607 | // clear all selection |
||
608 | if (main_self.idPull[id] != null) { |
||
609 | if (main_self.itemPull[id]["state"] == "enabled") { |
||
610 | if (main_self.idPull[id].className == "sub_item_selected") main_self.idPull[id].className = "sub_item"; |
||
611 | if (main_self.idPull[id].className == "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Selected") { |
||
612 | // main_self.idPull[id].className = "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Normal"; |
||
613 | // custom css |
||
614 | // console.log(main_self.itemPull[this.id]) |
||
615 | if (main_self.itemPull[id]["cssNormal"] != null) { |
||
616 | // alert(1) |
||
617 | main_self.idPull[id].className = main_self.itemPull[id]["cssNormal"]; |
||
618 | } else { |
||
619 | // default css |
||
620 | main_self.idPull[id].className = "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Normal"; |
||
621 | } |
||
622 | } |
||
623 | } |
||
624 | } |
||
625 | main_self._hidePolygon(id); |
||
626 | } |
||
627 | // added in 0.4 |
||
628 | // main_self._hidePolygon(main_self.idPrefix+main_self.topId); |
||
629 | main_self.menuTouched = false; |
||
630 | // |
||
631 | // hide all contextmenu polygons on mouseout |
||
632 | if (main_self.context) { |
||
633 | if (main_self.contextHideAllMode) { |
||
634 | main_self._hidePolygon(main_self.idPrefix+main_self.topId); |
||
635 | main_self.zInd = main_self.zIndInit; |
||
636 | } else { |
||
637 | main_self.zInd = main_self.zIndInit+main_self.zIndStep; |
||
638 | } |
||
639 | } |
||
640 | } |
||
641 | /* loading and parsing through xml, optimized in version 0.3 */ |
||
642 | this._doOnLoad = function() {} |
||
643 | /** |
||
644 | * @desc: loads menu data from an xml file and calls onLoadFunction when loading is done |
||
645 | * @param: xmlFile - an xml file with webmenu data |
||
646 | * @param: onLoadFunction - a function that is called after loading is done |
||
647 | * @type: public |
||
648 | */ |
||
649 | this.loadXML = function(xmlFile, onLoadFunction) { |
||
650 | if (onLoadFunction) this._doOnLoad = function() { onLoadFunction(); }; |
||
651 | this.callEvent("onXLS", []); |
||
652 | this._xmlLoader.loadXML(xmlFile); |
||
653 | } |
||
654 | /** |
||
655 | * @desc: loads menu data from an xml string and calls onLoadFunction when loading is done |
||
656 | * @param: xmlFile - an xml string with webmenu data |
||
657 | * @param: onLoadFunction - function that is called after loading is done |
||
658 | * @type: public |
||
659 | */ |
||
660 | this.loadXMLString = function(xmlString, onLoadFunction) { |
||
661 | if (onLoadFunction) this._doOnLoad = function() { onLoadFunction(); }; |
||
662 | this._xmlLoader.loadXMLString(xmlString); |
||
663 | } |
||
664 | View Code Duplication | this._buildMenu = function(t, parentId) { |
|
665 | // if (parentId==null) { parentId = this.topId;} |
||
666 | var u = 0; |
||
667 | for (var q=0; q<t.childNodes.length; q++) { |
||
668 | if (t.childNodes[q].tagName == this.itemTagName) { |
||
669 | var r = t.childNodes[q]; |
||
670 | var item = {}; |
||
671 | // basic |
||
672 | item["id"] = this.idPrefix+(r.getAttribute("id")||this._genStr(24)); |
||
673 | item["title"] = r.getAttribute("text")||""; |
||
674 | // images |
||
675 | item["imgen"] = r.getAttribute("img")||""; |
||
676 | item["imgdis"] = r.getAttribute("imgdis")||""; |
||
677 | item["tip"] = ""; |
||
678 | item["hotkey"] = ""; |
||
679 | // custom css |
||
680 | if (r.getAttribute("cssNormal") != null) { item["cssNormal"] = r.getAttribute("cssNormal"); } |
||
681 | // type |
||
682 | item["type"] = r.getAttribute("type")||"item"; |
||
683 | //#menu_checks:06062008{ |
||
684 | if (item["type"] == "checkbox") { |
||
685 | item["checked"] = (r.getAttribute("checked")!=null); |
||
686 | // set classname |
||
687 | item["imgen"] = "chbx_"+(item["checked"]?"1":"0"); |
||
688 | item["imgdis"] = item["imgen"]; |
||
689 | } |
||
690 | //#} |
||
691 | //#menu_radio:06062008{ |
||
692 | if (item["type"] == "radio") { |
||
693 | item["checked"] = (r.getAttribute("checked")!=null); |
||
694 | item["imgen"] = "rdbt_"+(item["checked"]?"1":"0"); |
||
695 | item["imgdis"] = item["imgen"]; |
||
696 | item["group"] = r.getAttribute("group")||this._genStr(24); |
||
697 | if (this.radio[item["group"]]==null) { this.radio[item["group"]] = new Array(); } |
||
698 | this.radio[item["group"]][this.radio[item["group"]].length] = item["id"]; |
||
699 | } |
||
700 | //#} |
||
701 | // enable/disable |
||
702 | item["state"] = (r.getAttribute("enabled")!=null||r.getAttribute("disabled")!=null?(r.getAttribute("enabled")=="false"||r.getAttribute("disabled")=="true"?"disabled":"enabled"):"enabled"); |
||
703 | item["parent"] = (parentId!=null?parentId:this.idPrefix+this.topId); |
||
704 | // item["complex"] = (((this.dLoad)&&(parentId!=null))?(r.getAttribute("complex")!=null?true:false):(this._buildMenu(r,item["id"])>0)); |
||
705 | item["complex"] = (this.dLoad?(r.getAttribute("complex")!=null?true:false):(this._buildMenu(r,item["id"])>0)); |
||
706 | if (this.dLoad && item["complex"]) { item["loaded"] = "no"; } |
||
707 | this.itemPull[item["id"]] = item; |
||
708 | // check for user data |
||
709 | for (var w=0; w<r.childNodes.length; w++) { |
||
710 | // added in 0.4 |
||
711 | var tagNm = r.childNodes[w].tagName; |
||
712 | if (tagNm != null) { tagNm = tagNm.toLowerCase(); } |
||
713 | // |
||
714 | if (tagNm == this.userDataTagName) { |
||
715 | var d = r.childNodes[w]; |
||
716 | if (d.getAttribute("name")!=null) { this.userData[item["id"]+"_"+d.getAttribute("name")] = (d.firstChild!=null&&d.firstChild.nodeValue!=null?d.firstChild.nodeValue:""); } |
||
717 | } |
||
718 | // extended text, added in 0.4 |
||
719 | if (tagNm == this.itemTextTagName) { item["title"] = r.childNodes[w].firstChild.nodeValue; } |
||
720 | // tooltips, added in 0.4 |
||
721 | if (tagNm == this.itemTipTagName) { item["tip"] = r.childNodes[w].firstChild.nodeValue; } |
||
722 | // hotkeys, added in 0.4 |
||
723 | if (tagNm == this.itemHotKeyTagName) { item["hotkey"] = r.childNodes[w].firstChild.nodeValue; } |
||
724 | // hrefs |
||
725 | if (tagNm == this.itemHrefTagName && item["type"] == "item") { |
||
726 | item["href_link"] = r.childNodes[w].firstChild.nodeValue; |
||
727 | if (r.childNodes[w].getAttribute("target") != null) { item["href_target"] = r.childNodes[w].getAttribute("target"); } |
||
728 | } |
||
729 | } |
||
730 | u++; |
||
731 | } |
||
732 | } |
||
733 | return u; |
||
734 | } |
||
735 | /* parse incoming xml */ |
||
736 | View Code Duplication | this._xmlParser = function() { |
|
737 | if (main_self.dLoad) { |
||
738 | var t = this.getXMLTopNode("menu"); |
||
739 | parentId = (t.getAttribute("parentId")!=null?t.getAttribute("parentId"):null); |
||
740 | if (parentId == null) { |
||
741 | // alert(1) |
||
742 | // main_self.idPrefix = main_self._genStr(12); |
||
743 | main_self._buildMenu(t, null); |
||
744 | main_self._initTopLevelMenu(); |
||
745 | } else { |
||
746 | main_self._buildMenu(t, main_self.idPrefix+parentId); |
||
747 | main_self._addSubMenuPolygon(main_self.idPrefix+parentId, main_self.idPrefix+parentId);//, main_self.idPull[main_self.idPrefix+parentId]); |
||
748 | if (main_self.menuSelected == main_self.idPrefix+parentId) { |
||
749 | var pId = main_self.idPrefix+parentId; |
||
750 | var isTop = main_self.itemPull[main_self.idPrefix+parentId]["parent"]==main_self.idPrefix+main_self.topId; |
||
751 | var level = ((isTop&&(!main_self.context))?main_self.dirTopLevel:main_self.dirSubLevel); |
||
752 | var isShow = false; |
||
753 | if (isTop && main_self.menuModeTopLevelTimeout && main_self.menuMode == "web" && !main_self.context) { |
||
754 | var item = main_self.idPull[main_self.idPrefix+parentId]; |
||
755 | if (item._mouseOver == true) { |
||
756 | var delay = main_self.menuModeTopLevelTimeoutTime - (new Date().getTime()-item._dynLoadTM); |
||
757 | if (delay > 1) { |
||
758 | item._menuOpenTM = window.setTimeout(function(){ main_self._showPolygon(pId, level); }, delay); |
||
759 | isShow = true; |
||
760 | } |
||
761 | } |
||
762 | } |
||
763 | if (!isShow) { main_self._showPolygon(pId, level); } |
||
764 | } |
||
765 | main_self.itemPull[main_self.idPrefix+parentId]["loaded"] = "yes"; |
||
766 | // console.log(main_self.loaderIcon) |
||
767 | if (main_self.loaderIcon == true) { main_self._updateLoaderIcon(main_self.idPrefix+parentId, false); } |
||
768 | } |
||
769 | this.destructor(); |
||
770 | main_self.callEvent("onXLE",[]); |
||
771 | } else { |
||
772 | var t = this.getXMLTopNode("menu"); |
||
773 | // alert(3) |
||
774 | // main_self.idPrefix = main_self._genStr(12); |
||
775 | main_self._buildMenu(t, null); |
||
776 | main_self.init(); |
||
777 | main_self.callEvent("onXLE",[]); |
||
778 | main_self._doOnLoad(); |
||
779 | } |
||
780 | } |
||
781 | this._xmlLoader = new dtmlXMLLoaderObject(this._xmlParser, window); |
||
782 | /* show sublevel item */ |
||
783 | View Code Duplication | this._showSubLevelItem = function(id,back) { |
|
784 | if (document.getElementById("arrow_" + this.idPrefix + id) != null) { document.getElementById("arrow_" + this.idPrefix + id).style.display = (back?"none":""); } |
||
785 | if (document.getElementById("image_" + this.idPrefix + id) != null) { document.getElementById("image_" + this.idPrefix + id).style.display = (back?"none":""); } |
||
786 | if (document.getElementById(this.idPrefix + id) != null) { document.getElementById(this.idPrefix + id).style.display = (back?"":"none"); } |
||
787 | } |
||
788 | /* hide sublevel item */ |
||
789 | this._hideSubLevelItem = function(id) { |
||
790 | this._showSubLevelItem(id,true) |
||
791 | } |
||
792 | // generating id prefix |
||
793 | this.idPrefix = this._genStr(12); |
||
794 | |||
795 | /* attach body events */ |
||
796 | this._bodyClick = function(e) { |
||
797 | e = e||event; |
||
798 | if (e.button == 2 || (_isOpera && e.ctrlKey == true)) return; |
||
799 | if (main_self.context) { |
||
800 | if (main_self.contextAutoHide && (!_isOpera || (main_self._isContextMenuVisible() && _isOpera))) main_self._hideContextMenu(); |
||
801 | } else { |
||
802 | if (main_self._clearAndHide) main_self._clearAndHide(); |
||
803 | } |
||
804 | } |
||
805 | this._bodyContext = function(e) { |
||
806 | e = e||event; |
||
807 | var t = String((e.srcElement||e.target).className); |
||
808 | if (t.search("dhtmlxMenu") != -1 && t.search("SubLevelArea") != -1) return; |
||
809 | var toHide = true; |
||
810 | var testZone = e.target || e.srcElement; |
||
811 | while (testZone != null) { |
||
812 | if (testZone.id != null) if (main_self.isContextZone(testZone.id)) toHide = false; |
||
813 | if (testZone == document.body) toHide = false; |
||
814 | testZone = testZone.parentNode; |
||
815 | } |
||
816 | if (toHide) main_self.hideContextMenu(); |
||
817 | } |
||
818 | |||
819 | if (typeof(window.addEventListener) != "undefined") { |
||
820 | window.addEventListener("click", this._bodyClick, false); |
||
821 | window.addEventListener("contextmenu", this._bodyContext, false); |
||
822 | } else { |
||
823 | document.body.attachEvent("onclick", this._bodyClick); |
||
824 | document.body.attachEvent("oncontextmenu", this._bodyContext); |
||
825 | } |
||
826 | |||
827 | // add menu to global store |
||
828 | this._UID = this._genStr(32); |
||
829 | dhtmlxMenuObjectLiveInstances[this._UID] = this; |
||
830 | |||
831 | /* events */ |
||
832 | dhtmlxEventable(this); |
||
833 | // |
||
834 | return this; |
||
835 | } |
||
836 | dhtmlXMenuObject.prototype.init = function() { |
||
2221 | }; |